<?

Class IncludeScript {

	private static $instancia;
	private $includeScript = '/minify.php';
	private $scripts = array();
	private $document_root;
	private $md5_config_file = 'cache/minify/md5.inc.php';
	private $md5 = array();
	
	function __construct () {
		$this->md5 = unserialize(file_get_contents(CONFIG_DOCUMENT_ROOT.$this->md5_config_file));
	}

	public static function getInstance()
	{
	  if (  !self::$instancia instanceof self)
	  {
	     self::$instancia = new self;
	  }
	  return self::$instancia;
	}

	function generateSrc ($arr=false) {
		if (!$arr || !is_array($arr)) return;
		
		$src = $hash = '';
		foreach ($arr as $s) 
			if (!in_array($s, $this->scripts)) {
				$src .= 's[]='.$s.'&';
				$hash .= $this->md5[$s];
			}
		// Agrego los scripts al array de scripts totales y elimino los duplicados
		$this->scripts = array_unique(array_merge($this->scripts, $arr));
		return $src.$hash;
	}

	function css ($arr=false) {
		$src = $this->generateSrc($arr);
		return '<link rel="stylesheet" type="text/css" href="'.str_replace('.php', '.css', $this->includeScript).'?'.$src.'" />';
	}

	function js ($arr=false) {
		$src = $this->generateSrc($arr);
		return '<script type="text/javascript" src="'.str_replace('.php', '.js', $this->includeScript).'?'.$src.'"></script>';
	}

}

?>
